<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePrintTemplateTable extends Migration
{
    /**
     * 数据表名称
     * @var string
     */
    private $tableName = 'print_template';

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create($this->tableName, function (Blueprint $table) {
            // 数据表类型
            $table->engine = 'InnoDB';
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';

            // 数据表字段
            $table->bigIncrements('tpl_id')->comment('模板主键');
            $table->string('mode', 100)->comment('分类标识');
            $table->string('title', 30)->comment('显示标题');
            $table->double('width')->nullable()->comment('标签宽度');
            $table->double('height')->nullable()->comment('标签高度');
            $table->bigInteger('user_id', false, true)->nullable()->comment('创建用户');
            $table->string('cover', 150)->nullable()->comment('封面图片');
            $table->text('header')->nullable()->comment('页眉内容');
            $table->text('footer')->nullable()->comment('页脚内容');
            $table->text('thead')->nullable()->comment('页头内容');
            $table->text('tfoot')->nullable()->comment('页尾内容');
            $table->text('lists')->nullable()->comment('列表内容');
            $table->text('tpl_desc')->nullable()->comment('模板描述');
            $table->dateTime('created_at')->comment('数据创建时间');
            $table->timestamp('updated_at')->comment('最后更新时间')->default(DB::raw('CURRENT_TIMESTAMP'));

            // 数据表索引
            $table->index(['mode']);
        });
        // 设置数据表备注信息
        DB::statement("ALTER TABLE `".env('DB_PREFIX')."{$this->tableName}` COMMENT'打印模板表'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists($this->tableName);
    }
}
